package com.zhangxun.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhangxun.domain.User;
import com.zhangxun.service.UserService;
import com.zhangxun.util.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/p/user")
@Api(tags = "用户接口管理")
public class UserController {

    @Autowired
    private UserService userService;

    @PutMapping("setUserInfo")
    @ApiOperation("添加用户从微信获取的昵称和头像接口")
    public ResponseEntity<Boolean> setUserInfo(User user){
        String userId = SecurityUtil.getWxUserId();
        user.setUserId(userId);
        boolean save = userService.updateById(user);

        return ResponseEntity.ok(save);

    }

    @PostMapping("/listByIds")
    public List<User> selectUserByIdS(@RequestBody List<String> userIdList){
        List<User> userList = userService.list(new LambdaQueryWrapper<User>()
                .select(User::getUserId, User::getPic, User::getNickName)
                .in(User::getUserId, userIdList));

        return userList;
    }


    /**
     * 远程调用通过用户id查询用户
     * @param wxUserId
     * @return
     */
    @GetMapping("/selectPhoneNum/{wxUserId}")
    User selectPhoneNum(@PathVariable String wxUserId){
        User user = userService.getById(wxUserId);
        return user;
    }

}
